var util = require('../../utils/util.js');
var WxParse = require('../../wxParse/wxParse.js');
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: "100%",
    hunterInfo:{},
    adviseProId:null,
    ordeschangeInfo:{}, 
    ordesinterviewInfo:{},
    ordesupInfo:{},
    ordesalaryInfo:{},
    ordeleaveInfo:{},
    avatarUrl: '/images/default_avatar.png',
    userInfo: '',
    showEvalute: [],
    showArt:{},
    isHaveResume: null,
    nonet: true ,
    currentTab: 0, // tab切换 
    serviceTags:[],
    bestdomains:[],
    iteminfo:{},
    itemName:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var hunterId = options.hunterid;
    var that = this;

    util.post(app.api.getHunterDetail, { hunterid: hunterId},function(res){
      //获取猎头详情
      that.setData({
        hunterInfo: res.data,
      });
     
      
    
      var serviceTagstr = that.data.hunterInfo.serviceTags;
      var serviceTagstrArr = serviceTagstr.split(",");
      console.log(serviceTagstrArr);
      that.setData({
        serviceTags : serviceTagstrArr
      });

      var bestdomainstr = that.data.hunterInfo.bestdomain;
      var bestdomainstrArr = bestdomainstr.split(",");
      console.log(bestdomainstrArr);
      that.setData({
        bestdomains: bestdomainstrArr
      });
    
    });

    util.post(app.api.getOrderDescList, { hunterid: hunterId},function(res){
      console.log(res.data);
      var msg=res.msg;
      var change = res.data.change
      var interview = res.data.interview
      var up = res.data.up
      var salary=res.data.salary
      var leave = res.data.leave
      if(msg==5){
        that.setData({
          ordeschangeInfo:change,
          ordesinterviewInfo:interview,
          ordesupInfo: up,
          ordesalaryInfo: salary,
          ordeleaveInfo: leave
        });
      } else if (msg == 4) {
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview,
          ordesupInfo: up,
          ordesalaryInfo: salary
        });
      }else if(msg==3){
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview,
          ordesupInfo: up
        });
      }else if(msg==2){
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview
        });
      }else if(msg==1){
        that.setData({
          ordeschangeInfo: change
        });
      }
 
    });

    util.post(app.api.selectByArticle, { hunterid: hunterId, pageSize:3 }, function (res) {
      console.log(res.data);
      that.setData({
        showArt: res.data,
      });
    });

    util.post(app.api.selectByEvaId, { hunterid: hunterId}, function (res) {
      console.log(res.data);
      that.setData({
        showEvalute: res.data
      }); 
    });

    that.setData({
      avatarUrl: that.data.showEvalute.buyHeadImg != null ? that.data.showEvalute.buyHeadImg : '/images/default_avatar.png',
      userInfo: app.getUserInfo()
    });
    //判断是否有简历
    if (app.globalData.openid != null) {
      util.post(app.api.isHaveResume, { unionid: app.globalData.unionid }, function (res) {
        console.log(res.data)
        that.setData({
          isHaveResume: res.data
        });
        wx.setStorageSync('isHaveResume', that.data.isHaveResume);
      });
    };
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          clientHeight: res.windowHeight
        });
      }
    });

  },
  radioChange:function(event){
    var that = this;
    var radioValue = event.detail.value;
    console.log("radioValue="+radioValue);
    util.post(app.api.getOrderDescId, { oritemid: radioValue }, function (res) {
      console.log("已选的咨询项目" + res.data);
      that.setData({
        iteminfo: res.data,
        adviseProId: radioValue,
        itemName:res.data.name
      });
    });
  },
  isSendTap: function (event) {
    var that=this;
    // console.log("check service"+that.data.radioPro);
    // console.log(111, that.data.isHaveResume)
    // 切换页面
    var phone = wx.getStorageSync('phone');
    if (app.globalData.openid == null){
      wx.showModal({
        title: '请先登录',
        content: '请微信授权登录，并完善您的资料',
        success: function (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pages/user/index'
            });
          } else if (res.cancel) {
          }
        }
      })
    }else if (that.data.isHaveResume == null || that.data.isHaveResume == 'binded' || that.data.isHaveResume == 'generated'){
      
      wx.showModal({
        title: '完善简历',
        content: '请完善您的资料，即可预约顾问',
        success: function (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pages/web-view/web-view'
            });
          } else if (res.cancel) {
          }
        }
      })
    }else{
      // console.log("薪酬分析*=="+that.data.itemName.indexOf("薪酬谈判"));
      // if (that.data.itemName.indexOf("薪酬谈判") >=0){
      //   app.alert("因薪资谈判服务需提前收集您的相关资料及制定总体薪酬方案，需加上总体薪酬分析及合理化建议服务（建议在offer流程中的候选人选择此项目）");
      // }else{
      console.log("that.data.adviseProId:" + that.data.adviseProId);
        wx.navigateTo({
          url: '../hunter-orderitem/hunter-orderitem?hunter=' + JSON.stringify(this.data.hunterInfo) + '&adviseProId=' + that.data.adviseProId + '&adviseProName=' + that.data.itemName
        });
      // }
    }
  },

  //关闭成功提示
  closeTap: function () {
    this.setData({
      mode: true,
      height: "100%"
    })
  },

  //更多文章
  moreartTap: function (event) {
    var that=this;
    var id = that.data.hunterInfo.id; // 当前id
    console.log("微信详情id获取=" + id)
    wx.navigateTo({
      url: '../leader/stories?hunterid='+ id,
    })
  },
  //跳转微信文章
  artTap: function (event) {
    var id = event.currentTarget.dataset.url; // 当前id
    console.log("微信详情id获取=" + id)
    // 切换页面
    wx.navigateTo({
      url: '../leader/stories/stories?url=' + id
    });
  },

  //分享
  onShareAppMessage: function (res) {
    var that = this;
    console.log(that.data.hunterInfo);
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    var title = that.data.hunterInfo.name + '' + that.data.hunterInfo.workage +'年'+ '【' + that.data.hunterInfo.bestdomain + '】';
    return {
      title: title,
      path: 'pages/hunter-detail/hunter-detail?hunterid=' + that.data.hunterInfo.id,
      data: that.data.hunterInfo,
      success: function (res) {
        // 转发成功
        console.log(res);
      },
      fail: function (res) {
        console.log(res)
        // 转发失败
      }
    }
  },

  //滑动切换tab
  bindChangeTab: function (e) {
    this.setData({ currentTab: e.detail.current });
  },

  //点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      this.setData({
        currentTab: e.target.dataset.current
      })
    }

  },
  onShow:function(){
    var that = this;
    wx.getNetworkType({
      success: function (res) {
        // 返回网络类型, 有效值：
        // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
        var networkType = res.networkType
        console.log("networkType=" + networkType);
        if (networkType == "none") {
          that.setData({
            nonet: false,
            submitdisabled: true
          })
        }
      }
    })
  }
})